package com.rongshu.view.penpal.activity;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.utils.Constant;
import com.rongshu.view.base.BaseActivity;
import com.rongshu.view.base.mvp.INetView;
import com.rongshu.view.penpal.bean.PenpalMessageResponse;
import com.rongshu.view.penpal.present.PenpalManagerPresenter;
import com.utils.FastClickUtils;
import com.widget.SwitchButton;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * created by zhengweis on 2018/11/6.
 * description：笔友会管理页面
 */
public class PenpalManagerActivity extends BaseActivity<PenpalManagerPresenter> implements INetView {
    @BindView(R.id.head_middle)
    TextView headMiddle;
    @BindView(R.id.head_right)
    TextView headRight;
    @BindView(R.id.edit_message)
    RelativeLayout editMessage;
    @BindView(R.id.note_manager)
    RelativeLayout noteManager;
    @BindView(R.id.member_manager)
    RelativeLayout memberManager;
    @BindView(R.id.verify)
    RelativeLayout verify;
    @BindView(R.id.member_verify)
    SwitchButton memberVerify;
    @BindView(R.id.note_open)
    SwitchButton noteOpen;
    @BindView(R.id.notice_manager)
    RelativeLayout noticeManager;
    @BindView(R.id.verify_layout)
    RelativeLayout verifyManager;
    @BindView(R.id.open_layout)
    RelativeLayout openManager;
    private PenpalMessageResponse.ResponseBean.ModelBean model;
    private int penpalId;

    @Override
    protected int initLayout() {
        return R.layout.activity_penpal_manager;
    }

    @Override
    protected void initView() {
        headMiddle.setText("笔友会管理");
        Intent intent = getIntent();
        if (intent != null) {
            model = (PenpalMessageResponse.ResponseBean.ModelBean) intent.getSerializableExtra("PenpalModel");

        }
        if (model != null) {
            penpalId = model.getPenpalwill_id();
            if (model.getRank() != 1) {
                editMessage.setVisibility(View.GONE);
                noteManager.setVisibility(View.GONE);
                verifyManager.setVisibility(View.GONE);
                openManager.setVisibility(View.GONE);
            }
            memberVerify.setChecked(model.getRatify());
            noteOpen.setChecked(model.getIspublic());
        }
    }

    @Override
    protected void initData() {
        setPresenter(new PenpalManagerPresenter(this), this);
        memberVerify.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (model != null && !FastClickUtils.isFastClick()) {
                    presenter.joinPenpalSwitch(model.getPenpalwill_id());
                }
            }
        });
        noteOpen.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (model != null && !FastClickUtils.isFastClick()) {
                    presenter.setPostIsPublic(model.getPenpalwill_id());
                }
            }
        });
    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    @OnClick({R.id.edit_message, R.id.note_manager, R.id.member_manager, R.id.verify, R.id.head_left, R.id.notice_manager})
    public void onViewClicked(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.edit_message://编辑资料
                intent.setClass(this, EditPenpalActivity.class);
                intent.putExtra(Constant.PENPAL_ID, penpalId);
                startActivity(intent);
                break;
            case R.id.notice_manager://公告管理
                intent.setClass(this, PenpalNoticeActivity.class);
                intent.putExtra(Constant.PENPAL_ID, penpalId);
                startActivity(intent);
                break;
            case R.id.note_manager://帖子管理
                intent.setClass(this, NoteManagerActivity.class);
                intent.putExtra(Constant.PENPAL_ID, penpalId);
                startActivity(intent);
                break;
            case R.id.member_manager://成员管理
                intent.setClass(this, MemberManagerActivity.class);
                intent.putExtra(Constant.PENPAL_ID, penpalId);
                intent.putExtra(Constant.PENPAL_MEMBER_OPTION, 1);
                startActivity(intent);
                break;
            case R.id.verify://入会审核
                intent.setClass(this, MemberVerifyActivity.class);
                intent.putExtra(Constant.PENPAL_ID, penpalId);
                startActivity(intent);
                break;
            case R.id.head_left:
                finish();
                break;
        }
    }

    @Override
    public void success(Object object, int tag) {

    }

    @Override
    public void faild(Object object, int tag) {

    }
}
